package com.master5.grocerylist.deprecated;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import com.google.gson.Gson;
import com.master5.grocerylist.credentials.Credentials;

public class CredentialsClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		URL url;
		
		try {
			url = new URL("http://grocerylistserv.appspot.com/api/login/auth/yigit/bekir");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("GET");
			conn.setRequestProperty("Accept", "application/json");
			conn.setUseCaches(false);
			conn.setAllowUserInteraction(false);
			
			conn.connect();
			
			if (conn.getResponseCode() != 200) {
				throw new RuntimeException("Failed : HTTP error code : "
						+ conn.getResponseCode());
			}
			
			BufferedReader br = new BufferedReader(new InputStreamReader(
					(conn.getInputStream())));
		 
			String output;
			String json = "";
			System.out.println("Output from Server .... \n");
			while ((output = br.readLine()) != null) {
				System.out.println(output);
				json += output + "\n";
			}
	 
			conn.disconnect();
			
			Credentials cr = new Gson().fromJson(json, Credentials.class);
			
			System.out.println("Password = " + cr.getPassword());
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
